﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Elasticsearch.Synchronize.Domain.Events;
using Elasticsearch.Synchronize.Domain.Interface;

namespace Elasticsearch.Synchronize.DomainEventHandler.Handler
{
    public class ScanSynchronizeRuleEventHandler : MediatR.NotificationHandler<ScanSynchronizeRuleDomainEvent>
    {
        private readonly ISynchronizeRuleRepository _repository;

        public ScanSynchronizeRuleEventHandler(ISynchronizeRuleRepository repository)
        {
            _repository = repository;
        }

        protected override void HandleCore(ScanSynchronizeRuleDomainEvent notification)
        {
            Console.WriteLine("SynchronizeRule.Scan()");
            var rules = _repository.GetValidRules();
            foreach (var rule in rules)
            {
                var target = notification.SynchronizeRule.Merge(rule);
                target.GetRuleData();
            }
        }
    }
}